package com.lin.sqltool.factory;




import com.lin.sqltool.service.ConnectionService;
import com.lin.sqltool.service.impl.MySQLConnectionServiceImpl;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ConnectionServiceFactory {


    private static final ConcurrentMap<String, ConnectionService> SERVICES = new ConcurrentHashMap<>();

    static {
        // 初始化已知数据库类型的服务实例
        SERVICES.put("mysql", new MySQLConnectionServiceImpl());

    }

    public static ConnectionService getService(String databaseType) {
        // 检查缓存中是否存在实例
        ConnectionService service = SERVICES.get(databaseType);
        if (service == null) {
            throw new IllegalArgumentException("不支持的数据库类型: " + databaseType);
        }
        return service;
    }

}
